package com.myapi.ModelPoker;
import java.util.Set;



/**
 * CombinedHands are Two pair and Full house
 * @author Release by Yoan Olivier 
 *
 */
public class CombinedHand extends RankedHand implements Comparable {

	private Card firstInterestCard;
	private Card secondInterestCard;
	
	/**
	 * Constructor
	 * @param rank
	 * @param cards
	 * @param interestCard1
	 * @param interestCard2
	 */
	public CombinedHand(int rank, Set<Card> cards, Card interestCard1, Card interestCard2) {
		super(rank, cards);		
		firstInterestCard = interestCard1;
		secondInterestCard = interestCard2;
	}
        
        public String rankToString() {
            String outRank = "";
            switch(getRank()) {
                case 2: outRank = "Two pair"; break;
                case 6: outRank = "Full house"; break;
            }
            return outRank;
        }
        
	
	private int getFirstCardValue() {
		return firstInterestCard.getValue();
	}
	
	private int getSecondCardValue() {
		return secondInterestCard.getValue();
	}
		
	public int compareTo(Object o) {
		assert o instanceof RankedHand;
		RankedHand hand = (RankedHand) o;
		int handRank = hand.getRank();
		if(getRank() > handRank) {
			return 1;
		} else if(getRank() < handRank) {
			return -1;
		} else {  //same rank, so must also be a CombinedHand
			CombinedHand cHand = (CombinedHand) o;
			if(getFirstCardValue() > cHand.getFirstCardValue())
				return 1;
			else if(getFirstCardValue() < cHand.getFirstCardValue())
				return -1;
			else if(getSecondCardValue() > cHand.getSecondCardValue())
				return 1;
			else if(getSecondCardValue() < cHand.getSecondCardValue())
				return -1;
			else {
				return compareHighCards(getCards(), cHand.getCards());
			}			
		}
	}

}
